<template>
  <div class="index">
    <commonHeader></commonHeader>
    <router-view />
    <engine :modelInfo="modelInfo" @finishProgress="finishProgress" v-show="!$route.meta.noModel"></engine>
    <commonButton></commonButton>
  </div>
</template>

<script setup lang="ts">
import commonHeader from "@/components/commonHeader.vue";
import commonButton from "@/components/commonButton.vue";
import engine from '@/components/engine.vue'

let modelInfo = [
  // {
  //   "dataSetId": '3a153a0ce5994d7f5adf684c14c5c75f',
  //   "resourcesAddress": "https://engine3.bjblackhole.com/engineweb/api/autoconvert/EngineRes/RequestEngineRes?dir=url_res05&path=3a153a0ce5994d7f5adf684c14c5c75f"
  // },
  // {
  //   "dataSetId": "3a153a0bacb308092ab3318152413457",
  //   "resourcesAddress": "https://engine3.bjblackhole.com/engineweb/api/autoconvert/EngineRes/RequestEngineRes?dir=url_res05&path=3a153a0bacb308092ab3318152413457"
  // },
  // {
  //   "dataSetId": "3a15c081bf164232db95c3d4cc1cef74",
  //   // "dataSetId": "3a15c081-bf16-4232-db95-c3d4cc1cef74",
  //   "resourcesAddress": "https://engine3.bjblackhole.com/engineweb/api/autoconvert/EngineRes/RequestEngineRes?dir=url_res05&path=3a15c081bf164232db95c3d4cc1cef74"
  // },
  //大场景
  {
    dataSetId: '3a1824018e2a0842625bf05d7690c698',
    resourcesAddress: 'https://engine3.bjblackhole.com/engineweb/api/autoconvert/EngineRes/RequestEngineRes?dir=url_res04&path=3a1824018e2a0842625bf05d7690c698'
  },
  //厂房
  {
    dataSetId: '3a175c85347226b66787f897eb7834f6',
    resourcesAddress: 'https://engine3.bjblackhole.com/engineweb/api/autoconvert/EngineRes/RequestEngineRes?dir=url_res04&path=3a175c85347226b66787f897eb7834f6'
  },
  //渗滤液
  {
    dataSetId: '3a175c856897705edde305e571780607',
    resourcesAddress: 'https://engine3.bjblackhole.com/engineweb/api/autoconvert/EngineRes/RequestEngineRes?dir=url_res04&path=3a175c856897705edde305e571780607',
    useTransInfo:true,
    transInfo:[[1, 1, 1], [0, 0, 0, 1], [0.0, -383.466, 0.0]],
  },
]

const route = useRoute();

//设置大场景相机位置
const setCamera = () => {
  var camLoc = new window.BlackHole3D.RECamLoc();
  camLoc.camPos = [-11.989535566467708, 663.6377984459257, 391.5321123209033];
  camLoc.camRotate = [-0.012228622489278747, -0.5093501182225567, -0.8602246168243208, -0.020652517234780992];
  var locDelay = 0.5;
  var locTime = 1;
  window.BlackHole3D.Camera.setCamLocateTo(camLoc, locDelay, locTime);
}

// 设置相机位置-厂房
const setCamera2 = () => {
  var camLoc = new window.BlackHole3D.RECamLoc();
  camLoc.camPos = [1.0245197145794336, 148.7957925058299, 65.35735767857165];
  camLoc.camRotate = [-0.0806883308839443, 0.6309357605209067, 0.7653941630766403, -0.09788378049134393];
  var locDelay = 0.5;
  var locTime = 1;
  window.BlackHole3D.Camera.setCamLocateTo(camLoc, locDelay, locTime);
}

let isfinish = ref(false);
watch(() => route.path, (newPath, oldPath) => {
  if (!isfinish.value) {
    return;
  }
  // console.log(`Route changed from ${oldPath} to ${newPath}`);
  if (newPath == '/home') {

    //隐藏其他模型
    // window.BlackHole3D.BIM.setElemsValidState("3a153a0ce5994d7f5adf684c14c5c75f", [], false);
    // window.BlackHole3D.BIM.setElemsValidState("3a153a0bacb308092ab3318152413457", [], false);
    // window.BlackHole3D.BIM.setElemsValidState("3a15c081bf164232db95c3d4cc1cef74", [], false);
    window.BlackHole3D.BIM.setElemsValidState("3a175c85347226b66787f897eb7834f6", [], false);
    window.BlackHole3D.BIM.setElemsValidState("3a175c856897705edde305e571780607", [], false);
    //显示大场景
    window.BlackHole3D.BIM.setElemsValidState('3a1824018e2a0842625bf05d7690c698', [], true);
    setCamera();
  } else {

    //隐藏大场景
    window.BlackHole3D.BIM.setElemsValidState('3a1824018e2a0842625bf05d7690c698', [], false);
    //显示其他模型
    // window.BlackHole3D.BIM.setElemsValidState("3a153a0ce5994d7f5adf684c14c5c75f", [], true);
    // window.BlackHole3D.BIM.setElemsValidState("3a153a0bacb308092ab3318152413457", [], true);
    // window.BlackHole3D.BIM.setElemsValidState("3a15c081bf164232db95c3d4cc1cef74", [], true);
    window.BlackHole3D.BIM.setElemsValidState("3a175c85347226b66787f897eb7834f6", [], true);
    window.BlackHole3D.BIM.setElemsValidState("3a175c856897705edde305e571780607", [], true);
    setCamera2()
  }

}, { immediate: true });

const finishProgress = () => {
  isfinish.value = true;
  console.log('route.path', route.path);
  if (route.path == '/home') {
    // modelInfo = [
    //   {
    //     dataSetId: '3a1824018e2a0842625bf05d7690c698',
    //     resourcesAddress: 'https://engine3.bjblackhole.com/engineweb/api/autoconvert/EngineRes/RequestEngineRes?dir=url_res04&path=3a1824018e2a0842625bf05d7690c698'
    //   }
    // ]

    //隐藏其他模型
    // window.BlackHole3D.BIM.setElemsValidState("3a153a0ce5994d7f5adf684c14c5c75f", [], false);
    // window.BlackHole3D.BIM.setElemsValidState("3a153a0bacb308092ab3318152413457", [], false);
    // window.BlackHole3D.BIM.setElemsValidState("3a15c081bf164232db95c3d4cc1cef74", [], false);
    window.BlackHole3D.BIM.setElemsValidState("3a175c85347226b66787f897eb7834f6", [], false);
    window.BlackHole3D.BIM.setElemsValidState("3a175c856897705edde305e571780607", [], false);
    //显示大场景
    window.BlackHole3D.BIM.setElemsValidState('3a1824018e2a0842625bf05d7690c698', [], true);
    setTimeout(() => {
      setCamera();
    }, 200)

  } else {

    //隐藏大场景
    window.BlackHole3D.BIM.setElemsValidState('3a1824018e2a0842625bf05d7690c698', [], false);
    //显示其他模型
    // window.BlackHole3D.BIM.setElemsValidState("3a153a0ce5994d7f5adf684c14c5c75f", [], true);
    // window.BlackHole3D.BIM.setElemsValidState("3a153a0bacb308092ab3318152413457", [], true);
    // window.BlackHole3D.BIM.setElemsValidState("3a15c081bf164232db95c3d4cc1cef74", [], true);
    window.BlackHole3D.BIM.setElemsValidState("3a175c85347226b66787f897eb7834f6", [], true);
    window.BlackHole3D.BIM.setElemsValidState("3a175c856897705edde305e571780607", [], true);
    // setTimeout(() => {
    //   window.BlackHole3D.Model.loadDataSet(modelInfo, true);
    // }, 1000)
    setCamera2()
  }
}
</script>

<style lang="scss" scoped></style>
